/**
 * 该例程设置/读取海龟例程中的参数
 * 小海龟🐢运行方法：
 *                 1.roscore
 *                 2.rosrun turtlesim turtlesim_node
 *                 3.rosrun turtlesim turtle_teleop_key
 * 然后再运行当前可执行文件：
 *                   rosrun learning_parameter parameter_config
 */
#include <string>
#include <ros/ros.h>
#include <std_srvs/Empty.h>

int main(int argc, char **argv)
{
	int red, green, blue;

    ros::init(argc, argv, "parameter_config");
    ros::NodeHandle node, private_nh("~/private_ns"), nh("~");

    /*
	ros::param::get("/background_r", red);           // 读取背景颜色参数
	ros::param::get("/background_g", green);
	ros::param::get("/background_b", blue);
	ROS_INFO("Get Backgroud Color[%d, %d, %d]", red, green, blue);
	
	ros::param::set("/background_r", 255);	         // 设置背景颜色参数
	ros::param::set("/background_g", 0);
	ros::param::set("/background_b", 255);
	ROS_INFO("Set Backgroud Color[255, 0, 255]");

	ros::param::get("/background_r", red);           // 读取背景颜色参数
	ros::param::get("/background_g", green);
	ros::param::get("/background_b", blue);
	ROS_INFO("Re-get Backgroud Color[%d, %d, %d]", red, green, blue);
	
	ros::service::waitForService("/clear");          // 调用服务，刷新背景颜色
	ros::ServiceClient clear_background = node.serviceClient<std_srvs::Empty>("/clear");
	std_srvs::Empty srv;
	clear_background.call(srv);
	sleep(0.5);
	*/

	node.setParam("nh_string","hello NodeHandle"); //字符串
	nh.setParam("nh_string","hello NodeHandle");
	private_nh.setParam("nh_string","hello NodeHandle");
	std::string key;
	//使用节点句柄进行搜索的比较多，直接就是针对当前这个节点的命名空间搜索的，因此是带有命名空间的搜索
	//node.searchParam("nh_string",key);
	nh.searchParam("nh_string",key);
	//private_nh.searchParam("nh_string",key);
    //ros::param::search("nh_string",key);
    ROS_INFO("search key: %s",key.c_str());
	sleep(0.5);

    return 0;
}
